#include <iostream>
#include "d_except.h"

using namespace std;

class card
//Card's suit is an int between 1(clubs) and 4(spades)
//Card's value is an int between 1(ace) and 13(king)... or 14(ace) just in case
{
  friend ostream& operator<<(ostream &ostr, const card &c);

 public:
  card (int val=1 , int sut=4);

  int getSuit() const;
  int getValue() const;
  void setSuit(const int sut);
  void setValue(const int value);

 private:
  int suit;
  int value;
  
};

card::card (int val, int sut)
//Check if the int values passed are valid
//Throw exception if not
{
  if (val < 1 || val > 14) 
    throw (baseException("Bad value passed to card constructor!"));

  if (sut < 1 || sut > 4) 
    throw (baseException("Bad suit passed to card constructor!"));

  suit = sut;
  value = val;
}
    
int card::getSuit() const 
{
  return suit;
}

int card::getValue() const 
{
  return value;
}


ostream& operator<<(ostream &ostr, const card &c)
//Convert the private ints into actual card names
//Assumes the card is correctly constructed
//We call this a friend instead of using 
//getSuit and getValue to improve speed 
{
  switch(c.value)
  {
  case 1 : ostr << "Ace" << " of "; break;
  case 2 : ostr << 2 << " of "; break;
  case 3 : ostr << 3 << " of "; break;
  case 4 : ostr << 4 << " of "; break;
  case 5 : ostr << 5 << " of "; break;
  case 6 : ostr << 6 << " of "; break;
  case 7 : ostr << 7 << " of "; break;
  case 8 : ostr << 8 << " of "; break;
  case 9 : ostr << 9 << " of "; break;
  case 10 : ostr << 10 << " of "; break;
  case 11 : ostr << "Jack" << " of "; break;
  case 12 : ostr << "Queen" << " of "; break;
  case 13 : ostr << "King" << " of "; break;
  case 14 : ostr << "Ace" << " of "; break;
  }

  switch(c.suit)
  {
  case 1 : ostr << "Clubs"; break;
  case 2 : ostr << "Hearts"; break;
  case 3 : ostr << "Diamonds"; break;
  case 4 : ostr << "Spades"; break;
  }
  return ostr;
}
